(function($) {
	$.imageFileVisible = function(options) {
		// 默认选项
		var defaults = {
			// 包裹图片的元素
			wrapSelector : null,
			// <input type=file />元素
			fileSelector : null,
			formSelector : null,
			width : '100%',
			height : 'auto',
			errorMessage : "不是图片"
		};
		// Extend our default options with those provided.
		var opts = $.extend(defaults, options);
		$(opts.fileSelector).change(function() {
			var file = this.files[0];
			var imageType = /image.*/;
			if (file.type.match(imageType)) {
				var reader = new FileReader();
				reader.onload = function() {
					var img = new Image();
					img.src = reader.result;
					$(img).width(opts.width);
					$(img).height(opts.height);
					$(opts.wrapSelector).attr("src",img.src);
					//先保存图片
					$(options.formSelector).ajaxSubmit({
						type : 'POST',
						url : '/common/picUpload',
						success : function(data) {
							$("#picture").val(data.data);
						},
						error : function() {
							alert("上传失败，请检查网络后重试");
							return;
						}
					});
				};
				reader.readAsDataURL(file);
			} else {
				alert(opts.errorMessage);
			}
		});
	};
})(jQuery);